package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_Delay {


    public static final String Exchange_Business_delay_direct = "Exchange_Business_delay_direct";
    public static final String Queue_Business_delay_1 = "Queue_Business_delay_1";
    public static final String Business_RoutingKey_delay_1 = "Business_RoutingKey_delay_1";

    public static final String Exchange_Delay_direct = "Exchange_Delay_direct";
    public static final String Queue_Delay_1 = "Queue_Delay_1";
    public static final String Delay_RoutingKey_1 = "Delay_RoutingKey_1";


    @Bean(Exchange_Business_delay_direct)
    public Exchange exchange_Business_delay_1(){
        return ExchangeBuilder.directExchange(Exchange_Business_delay_direct).build();
    }

    @Bean(Queue_Business_delay_1)
    public Queue queue_Business_delay_1(){
        return QueueBuilder.durable(Queue_Business_delay_1)
                //.withArgument("x-dead-letter-exchange",Exchange_DeadLetter_1)
                //.withArgument("x-dead-letter-routing-key",Business_RoutingKey_1)
                //.withArgument("x-message-ttl", 10000)
                .deadLetterExchange(Exchange_Delay_direct)
                .deadLetterRoutingKey(Delay_RoutingKey_1)
                .ttl(1000*20)//ms
                .build();
    }

    @Bean
    public Binding binding_business_delay_1(
            @Qualifier(Queue_Business_delay_1) Queue queue,
            @Qualifier(Exchange_Business_delay_direct) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(Business_RoutingKey_delay_1).noargs();
    }

    @Bean(Exchange_Delay_direct)
    public Exchange Exchange_Delay_1(){
        return ExchangeBuilder.directExchange(Exchange_Delay_direct).build();
    }

    @Bean(Queue_Delay_1)
    public Queue Queue_Delay_1(){
        return QueueBuilder.durable(Queue_Delay_1).build();
    }


    @Bean
    public Binding binding_delay_2(
            @Qualifier(Queue_Delay_1) Queue queue,
            @Qualifier(Exchange_Delay_direct) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(Delay_RoutingKey_1).noargs();
    }
}
